<?php
class MHtml {
    const EOL = "\n";

    /**
     * Render XHTML Code for the specified tag name
     * @param String $tag : Tag name (a, p, div...)
     * @param Array $htmlOptions (optional) : HTML options to add to the tag (class, id...)
     * @param String $content (optional) : Content between start and end of tag. Default set to false for no content.
     * @return String : XHTML Code of the tag
     */
    public static function tag($tag, $htmlOptions=array(), $content=false){
        $return = '<'.$tag.self::renderHtmlOptions($htmlOptions);
        if ($content === false){
            $return .= '/>'.self::EOL;
        } else {
            $return .= '>'.$content.'</'.$tag.'>'.self::EOL;
        }
        return $return;
    }

    /**
     * Render HTML Options
     * @param Array $htmlOptions : HTML options to render
     * @return String : XHTML Code for the HTML options (key=value)
     */
    public static function renderHtmlOptions($htmlOptions){
        $return = '';
        foreach ($htmlOptions as $key=>$value){
            if ($key != 'content')
                $return .= ' '.$key.'="'.$value.'"';
        }
        return $return;
    }
}
?>
